#include "selectwindow.h"
#include "ui_selectwindow.h"

SelectWindow::SelectWindow(QTcpSocket * clientSocket,QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::SelectWindow)
    , clientSocket(clientSocket)
{
    ui->setupUi(this);
    QPixmap pixmap("../../../resource/2.jpg");

    // 创建一个QPalette实例
    QPalette palette;
    palette.setBrush(QPalette::Window, pixmap);

    // 设置窗口的调色板
    this->setPalette(palette);

    // 设置窗口标题
    this->setWindowTitle("功能界面");
}

void SelectWindow::on_InformationEditButton_clicked(){
    informationeditwindowPtr = new InformationEditWindow(clientSocket);
    informationeditwindowPtr->show();
    connect(informationeditwindowPtr,&InformationEditWindow::back,this,&SelectWindow::InformationEditWindow_closed);
    hide();
}

void SelectWindow::on_RegisterButton_clicked(){
    registerWindowPtr = new RegisterWindow(clientSocket);
    registerWindowPtr->show();
    connect(registerWindowPtr, &RegisterWindow::back, this, &SelectWindow::RegisterWindow_closed);
    hide();
}

void SelectWindow::on_CheckInformationButton_clicked(){
    allinformationwindowPtr = new AllInformationWindow(clientSocket);
    allinformationwindowPtr->show();
    connect(allinformationwindowPtr,&AllInformationWindow::back,this,&SelectWindow::AllInformationWindow_closed);
    hide();
}

void SelectWindow::on_CommunicationButton_clicked(){
    communicationwindowPtr = new CommunicationWindow(clientSocket);
    communicationwindowPtr->show();
    connect(communicationwindowPtr, &CommunicationWindow::back, this, &SelectWindow::CommunicationWindow_closed);
    hide();
}

void SelectWindow::CommunicationWindow_closed(){
    communicationwindowPtr->close();
    delete communicationwindowPtr;
    show();
}

void SelectWindow::RegisterWindow_closed(){
    registerWindowPtr->close();
    delete registerWindowPtr;
    show();
}

void SelectWindow::AllInformationWindow_closed(){
    allinformationwindowPtr->close();
    delete allinformationwindowPtr;
    show();
}

void SelectWindow::InformationEditWindow_closed(){
    informationeditwindowPtr->close();
    delete informationeditwindowPtr;
    show();
}

SelectWindow::~SelectWindow()
{
    delete ui;
}
